 {extend name="v1/layout/base"}
 {block name="content"}
 <div class="layuimini-main">
   <script type="text/html" id="toolbar">
     <div class="layui-btn-container">
       <button class="layui-btn layui-btn-black  layui-btn-sm" lay-event="reseve"><i class="layui-icon">&#xe63d;</i></button>
       <button class="layui-btn layui-btn-normal  layui-btn-sm" lay-event="add" data-url="/{:config('manage.manage_name')}/{:config('manage.version')}/System/shippingTemplateCreate/store_id/{$store_id}"><i class="layui-icon">&#xe654;</i>添加</button>
       <button class="layui-btn layui-btn-danger  layui-btn-sm" lay-event="delete" data-url="/{:config('manage.manage_name')}/{:config('manage.version')}/System/shippingTemplateDestroy"><i class="layui-icon">&#xe640;</i>删除选中</button>
     </div>
   </script>

   <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

   <script type="text/html" id="currentTableBar">
     <button class="layui-btn layui-btn-radius layui-btn-warm layui-btn-sm" lay-event="show" data-url="/{:config('manage.manage_name')}/{:config('manage.version')}/System/shippingTemplateEdit"><i class="layui-icon">&#xe642;</i>修改</button>
     <button class="layui-btn layui-btn-radius layui-btn-danger layui-btn-sm" lay-event="delete" data-url="/{:config('manage.manage_name')}/{:config('manage.version')}/System/shippingTemplateDestroy"><i class="layui-icon">&#xe640;</i>删除</button>
   </script>
 </div>
 {/block}
 {block name="myScript"}
 <script>
   layui.use(['form', 'table'], function() {
     var $ = layui.jquery,
       form = layui.form,
       store_id = '{$store_id}',
       table = layui.table;
     table.render({
       elem: '#currentTableId',
       url: '/{:config("manage.manage_name")}/{:config("manage.version")}/System/shippingTemplate',
       toolbar: '#toolbar',
       defaultToolbar: ['filter'],
       where: {
         store_id: store_id
       },
       cols: [
         [{
             type: "checkbox"
           },
           {
             field: 'shipping_type_id',
             width: '5%',
             title: 'ID',
             sort: true
           },
           {
             field: 'shipping_type_name',
             width: '10%',
             title: '运费模板名称'
           },
           {
             field: 'area_show',
             width: '25%',
             title: '配送地区'
           },
           {
             field: 'price_type',
             width: '10%',
             title: '计费方式'
           },
           {
             field: 'price',
             width: '10%',
             title: '运费'
           },
           {
             field: 'update_time',
             width: '15%',
             title: '最后更新时间'
           },
           {
             title: '操作',
             toolbar: '#currentTableBar',
             align: "center"
           }
         ]
       ],
       limits: [20, 150, 200, 250, 500, 1000],
       limit: 20,
       id: 'table_ids',
       page: true,
       skin: 'line'
     });

     // 顶部操作工具
     table.on('toolbar(currentTableFilter)', function(obj) {
       var url = $(this).attr('data-url'),
         store_id = '{$store_id}',
         keywords = $("#keywords").val();
       switch (obj.event) {
         case 'reseve':
           table.reload('table_ids');
           break;
         case 'add':
           var index = layer.open({
             title: '运费模板添加',
             type: 2,
             shade: 0.2,
             maxmin: true,
             shadeClose: true,
             area: ['100%', '100%'],
             content: url,
             cancel: function() {
               table.reload('table_ids', {
                 where: {
                   keywords: keywords,
                   store_id: store_id
                 }
               });
             }
           });
           break;
         case 'delete':
           const id_arr = getCheckValue();
           if (id_arr) {
             layer.msg('您确定要删除选中的运费模板吗？', {
               time: 0,
               btn: ['确定', '取消'],
               yes: function(index) {
                 layer.close(index);
                 https(url, {
                   id_str: id_arr
                 }, 'post', true, '正在执行删除').then(res => {
                   if (res.result_code == 200) {
                     table.reload('table_ids', {
                       where: {
                         keywords: keywords,
                         store_id: store_id
                       }
                     });
                   }
                 })
               },
               btn2: function(index) {
                 layer.close(index);
               }
             });
           } else {
             layer.msg("请选择需要操作的数据", {
               icon: 5,
               time: 1000
             });
           }
           break;
         case 'search':
           $("#xk-search-status").removeClass('xk-search-status');
           break;
         case 'back':
           var iframeIndex = parent.layer.getFrameIndex(window.name);
           window.parent.location.reload();
           parent.layer.close(iframeIndex);
           break;
       }
     })
     // 列表工具栏目
     table.on('tool(currentTableFilter)', function(obj) {
       var data = obj.data,
         event = obj.event,
         keywords = $("#keywords").val(),
         store_id = '{$store_id}',
         url = $(this).attr('data-url');
       url = url + '/shipping_type_id/' + data.shipping_type_id;
       switch (event) {
         case 'show':
           var index = layer.open({
             title: '运费模板' + data.shipping_type_name + '编辑',
             type: 2,
             shade: 0.2,
             maxmin: true,
             shadeClose: true,
             area: ['100%', '100%'],
             content: url,
             cancel: function() {
               table.reload('table_ids', {
                 where: {
                   keywords: keywords,
                   store_id: store_id,
                 }
               });
             }
           });
           break;
         case 'delete':
           //确定要删除吗？
           layer.msg('您确定要删除' + obj.data.shipping_type_name + '这个运费模板吗？', {
             time: 0, //不自动关闭
             btn: ['确定', '取消'],
             yes: function(index) {
               layer.close(index);
               https(url, {
                 id_str: obj.data.shipping_type_id
               }, 'post', true, '正在删除').then(res => {
                 if (res.result_code == 200) {
                   table.reload('table_ids', {
                     where: {
                       keywords: keywords,
                       store_id: store_id
                     }
                   });
                 }
               })
             },
             btn2: function(index) {
               layer.close(index);
             }
           });
           break;
       }
     })
     // 执行搜索
     $(".xk-dosearch").click(function() {
       var keywords = $("#keywords").val(),
         store_id = '{$store_id}';
       table.reload('table_ids', {
         page: {
           curr: 1
         },
         where: {
           keywords: keywords,
           store_id: store_id,
         }
       }, 'data');
     })
     // 获取选中项
     function getCheckValue() {
       var id_arr = [],
         id_str = '';
       var checkStatus = table.checkStatus('table_ids'),
         data = checkStatus.data;
       data.map(function(d) {
         id_arr.push(d.shipping_type_id);
       })
       id_str = id_arr.join(',');
       return id_str;
     }
   });
 </script>
 {/block}
